import { createSSRApp } from 'vue'
// 引入 Pinia
import { createPinia } from 'pinia'

import { createPersistedState } from 'pinia-plugin-persistedstate'
import App from './App'
import '@/utils/utils'

export function createApp() {
  const app = createSSRApp(App)

  // 实例化Pinia
  const pinia = createPinia()
    // 自定义pinia
    pinia.use(createPersistedState({
      key: (id) => `__persisted__${id}`,
      storage:{
        getItem: (key) => {
          return uni.getStorageSync(key)
        },
        setItem: (key, value) => {
          uni.setStorageSync(key, value)
        },
      }
    }))
  // 传递给项目应用
  app.use(pinia)
  return { app }
}